//
//  ValidationCodeViewController.m
//  tuanGG
//
//  Created by 微他 on 15/11/30.
//  Copyright (c) 2015年 weita. All rights reserved.
//

#import "ValidationCodeViewController.h"

@interface ValidationCodeViewController ()
@property (nonatomic,strong)UITextField *textfield;
@end

@implementation ValidationCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addnavigationTitle:@"验证订单号" navColor:@"4fd2be"];
    [self addInitView];
}
- (void)addInitView {
    self.view.backgroundColor = [UIColor colorWithHexString:@"f0efed"];
    _textfield = [[UITextField alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 40)];
    _textfield.backgroundColor = [UIColor whiteColor];
    _textfield.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    _textfield.leftViewMode = UITextFieldViewModeAlways;
    _textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
    _textfield.placeholder = @"请输入需要验证的订单号";
    [self.view addSubview:_textfield];

    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(_textfield.frame)+40, ScreenWidth-40, 40)];
    [button setTitle:@"验证" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    button.backgroundColor = [UIColor colorWithHexString:@"4fd2be"];
    button.layer.cornerRadius = 5;
    [button addTarget:self action:@selector(buttonBuild) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}
- (void)buttonBuild {
    if (_textfield.text.length != 12) {
        [Common addAlert:@"请输入12位数的订单号"];
    }else {
        [self Networking];
    }
}
- (void)Networking {
    NSLog(@"%@",[User_member instance].telephone);
    NSDictionary *dictionary = @{@"consumekey":_textfield.text,@"buytelephone":[User_member instance].telephone};
    [GLAFRequest startRequest:checkConsumeKey_url paramsDic:dictionary defaultdialog:YES ispost:YES handleSuccess:^(id sta, NSDictionary *paramsDic) {
        NSLog(@"%@",sta);
        if ([sta[@"code"]integerValue] == 1) {
            [Common addAlert:@"验证成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
    } doFinally:^(NSDictionary *paramsDic) {

    }];
}
@end
